Skip to content

fix(query): restricting by a union no longer raises TypeError - #1755

Open
dimitri-yatsenko wants to merge 1 commit into
masterfrom
fix/nested-union
Open

dimitri-yatsenko wants to merge 1 commit into
masterfrom
fix/nested-union

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

Fixes #1739

What changes

Restricting by a union raised TypeError: Union.make_sql() takes 1 positional argument but 2 were given. This affected:

  • A & (B + C) and A - (B + C)
  • a union whose left operand is a union, when the operands have secondary attributes, on fetch, len(), or use as a restriction. Such a union compiles arg2 - arg1, which restricts by the left operand.

make_condition now wraps a union operand in a subquery before building the IN (...) condition, as it already does for an aggregation or a dj.Top-limited expression. Two lines change in src/datajoint/condition.py.

No change for queries that work today

Every code path changed here raised before, so no query that runs today returns a different result. A union with no attributes in common with the restricted query still takes the existing true/false shortcut. A new test covers that case and passes before and after the change.

Relation to the 2.4 fix

Tests

New tests/integration/test_union_restriction.py, run on MySQL and PostgreSQL:

  • the nested union from the issue: 4 rows with NULLs, and len()
  • restriction and its complement by a union with secondary attributes, by the nested union, and by a union of primary keys only
  • restriction by a union with no common attributes, empty and non-empty

The full suite passes on both backends.

Restricting by a union raised TypeError because Union.make_sql takes no
field list. A union with secondary attributes restricts its right operand by
its left one, so a union whose left operand is a union failed the same way
when fetched or counted. make_condition now wraps a union operand in a
subquery, as it already does for an aggregation or a dj.Top-limited
expression.

Fixes #1739

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A union of a union with secondary attributes raises TypeError: a union is not put in a subquery when used as a restriction

1 participant